{extend name="base" /}
<!-- page specific plugin styles -->
{block name="plugin-styles"}{/block}
<!-- inline styles related to this page -->
{block name="inline-styles"}{/block}
<!-- breadcrumb -->
{block name="breadcrumbs"}
<ul class="breadcrumb">
    <li>
        <i class="ace-icon fa fa-home home-icon"></i>
        <a href="{:url('Index/index')}">首页</a>
    </li>
    <li class="active">仓库管理</li>
</ul>
<!-- /.breadcrumb -->
{/block}
<!-- PAGE CONTENT BEGINS -->
{block name="content"}
<div class="page-header">
    <h1>
        仓库列表
    </h1>
</div>
<!-- /.page-header -->

<div class="clearfix tableTools-container">
    <form class="pull-left form-inline" id='ajaxForm'>
        <div class="form-group">
            <label class="sr-only" for="goodsname">仓库名称</label>
            <div class="input-group">
                <span class="input-group-addon">仓库名称</span>
                <input type="text" class="form-control input-sm" name="name" autocomplete = "off" placeholder="请输入仓库名称">
            </div>
        </div>
        <div class="form-group">
            <button type="button" class="btn btn-xs btn-primary" id='add'>新增</button>
        </div>
    </form>
</div>
<div class="table-responsive">
    <table class="table table-bordered" id="DynamicTable">
       <tr>
           <th>ID</th>
           <th>名称</th>
           <th>状态</th>
           <th>操作</th>
       </tr>
       {foreach $list as $vo}
       <tr>
           <td>{$vo.id}</td>
           <td><input class="class="form-control input-sm"  type='text' name='name' value="{$vo.name}" onchange="updateName(this,{$vo.id})"></td>
          <td>
           {if condition="$vo.status == 1"}
           <span class='label label-success'>上线</span>
           {else}
           <span class='label label-warning'>下线</span>
           {/if}
           </td>
           <td>
           {if condition="$vo.status == 1"}
           <button class='btn btn-xs btn-success' onclick='offline({$vo.id})'>下线</button>
           {else}
           <button class='btn btn-xs btn-success' onclick='online({$vo.id})'>上线</button>
           {/if}
           </td>
       </tr>
       {/foreach}
    </table>
</div>

<!-- /.table-responsive -->
{/block}
<!-- PAGE CONTENT ENDS -->
<!-- page specific plugin scripts -->
{block name="plugin-scripts"}
<script src="/static/ace/assets/js/jquery.dataTables.min.js"></script>
<script src="/static/ace/assets/js/jquery.dataTables.bootstrap.min.js"></script>
{/block}
<!-- inline scripts related to this page -->
{block name="related-scripts"}
<script type="text/javascript">

$("#add").click(function(event) {
    /* Act on the event */
    var options={
        url:"/admin/goods/store_add_or_update",
        type:"POST",
        dataType:"json",
        data: {
        },
        success: function(json){
            if(json.returnCode==1){
                alert('保存成功');
                window.location.href='';
            }else{
                alert(json.returnMsg);
            }
        }
    };
    $("#ajaxForm").ajaxSubmit(options)
});
        
        function updateName(_ele,_id){
        	name = $(_ele).val()
        	$.ajax({
                url: '/admin/goods/store_add_or_update',
                type: 'POST',
                dataType: 'json',
                data: {id: _id,name:name},
            })
            .done(function(json) {
                console.log("success");
                if(json.returnCode==1){
                    alert(json.returnMsg);
                    window.location.href='';
                }else{
                    alert(json.returnMsg);
                }
            })
        }
        function online(_id) {
            
            $.ajax({
                url: '/admin/goods/store_online',
                type: 'POST',
                dataType: 'json',
                data: {id: _id},
            })
            .done(function(json) {
                console.log("success");
                if(json.returnCode==1){
                    alert(json.returnMsg);
                    window.location.href='';
                }else{
                    alert(json.returnMsg);
                }
            })
            
        }
        
        function offline(_id) {
            
            $.ajax({
                url: '/admin/goods/store_offline',
                type: 'POST',
                dataType: 'json',
                data: {id: _id},
            })
            .done(function(json) {
                console.log("success");
                if(json.returnCode==1){
                    alert(json.returnMsg);
                    window.location.href='';
                }else{
                    alert(json.returnMsg);
                }
            })
        }
        
</script>
{/block}